/**
 * 提交申请弹窗控制器
 */
import tem from './index.html'
import './index.less'
import $_fn from '~plugins'
class returnorderCtrl {
  constructor($scope,$rootScope,http,$ui,$state,$location,$timeout) {
    $scope.param = {}
    $scope.redErr = {}
    console.log('$scope.params', $scope.params,$location,$location.path(),$location.search())
    $scope.cancel = function () {
      $rootScope.$uiDirectiveModal.close() //关闭方法
    }
    //警告提示
    $scope.errorToast = function(text) {
      $ui.toast({text:text,type:'warning',position:'center',appendTo:'.wp-container'});
    }
    //成功提示
    $scope.successToast = function(text) {
        $ui.toast({text:text,type:'success',position:'center',appendTo:'.wp-container'});
    }
    $scope.remHight = function(){                                                 //去除报错高亮
      for(var i in $scope.redErr){
        $scope.redErr[i] = false
      }
    }
    $scope.ok=function (state) {
      if(!$scope.params.remark){
        $scope.redErr.remark=true
        $scope.errorToast('请填写退回原因')
        return
      }
      $scope.param.ids = $scope.params.oid+''
      $scope.param.remark = $scope.params.remark
      http.post('updateOrderBack.do',$scope.param,function (data) {
        if(data.errcode == 1){
          $scope.successToast(data.errmsg)
          $scope.cancel()
          if($rootScope.refreshPage){
            $rootScope.refreshPage(1,{s_id:2,sIds:3})
          }
        }else{
          $scope.errorToast(data.errmsg || '提交失败！')
        }
      })
    }
  }
}


returnorderCtrl.$inject = ['$scope','$rootScope','http','$ui','$state','$location','$timeout','$interval']
module.exports = angular.module('directive.returnorder', []).directive('returnorder', function() {
  return {
    restrict: 'E',
    template: tem,
    replace:true,
    controller: returnorderCtrl,
    scope: {
      params: '<'
    },
    link:function(){
      $_fn.clickBind()
    }
  }
}).name